<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>构建记录</title>
    <link rel="stylesheet" type="text/css" media="all" href="/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" media="all" href="/css/common.css"/>
    <script type="text/javascript" src="/layui/layui.all.js"></script>
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/myJs.js"></script>
    <link rel="stylesheet" type="text/css" media="all" href="/css/CaseManager.css"/>
</head>
<body>
<div class="layui-fluid">
    <div class="row">
        <div class="layui-col-sm12">
            <br/><br/><br/>

            <div class="layui-inline">
                <input class="layui-btn  layui-btn-primary"  style="width: 600px ;border:0" type="button" value="服务管理" onclick="one()" />
                <input class="layui-btn layui-btn-warm" style="width: 600px;border:0" type="button" value="服务状态"/>
                <input class="layui-btn  layui-btn-primary" style="width: 600px;border:0" type="button" value="部署申请" onclick="four()"/>
            </div>
            <br/><br/><br/>
            <div class="layui-col-xs4">
                搜索服务：
                <div class="layui-inline">
                    <input class="layui-input" name="buildName" id="buildName" />
                </div>
                <button class="layui-btn" data-type="reload">搜索</button>
            </div>
            <div class="layui-col-xs4">
                搜索负责人：
                <div class="layui-inline">
                    <input class="layui-input" name="BuildLeader" id="BuildLeader" />
                </div>
                <button class="layui-btn" data-type="reload">搜索</button>
            </div>
            <div class="layui-col-xs4">
                审核状态：
                <div class="layui-input-inline ">
                    <div class="layui-form">
                    <select  name="AuditSelect" id="eAudit" >
                        <option value="">全选</option>
                        <option value="1">待审核</option>
                        <option value="2">已审核</option>
                    </select>
                    </div>
                </div>
                <button class="layui-btn" data-type="reload">搜索</button>
            </div>
            <table class="layui-table" id="BaseServerList" lay-filter="table"></table>
        <!--<a href="/server/baseServer" style="margin-top:10px;" target="_blank" class="layui-btn">点击返回</a>-->
            <!--<div class="layui-col-xs12">-->
                <!--<input class="layui-btn layui-btn-warm" type="button" value="进入审核页" onclick="go()"/>-->
            <!--</div>-->
        </div>
    </div>
</div>

<script>


    layui.use('form', function(){
        var form = layui.form;

        form.render();
        form.on('submit(in)', function(data){
            var S = $('#input').val();
            alert(S);
            if (S=='admin'){
                loadPage("/server/buildAuditList")
            }
        });
    });
    layui.use('table', function(){
        var table = layui.table,$ = layui.jquery;
        table.render({
            elem: '#BaseServerList'
            ,url:'/server/getbuildRecordForPaging'
            ,cellMinWidth: 80
            ,page: true
            ,id:'buildRecordID'
            ,cols: [[
                {field:'buildId', title: 'ID',align:'center', width: 60}
                ,{field:'vServerName', title: '服务名', align:'center', width: 160}
              //  ,{field:'vBranch', title: '包名', align:'center', minWidth: 100}
                ,{field:'vDev', title: '构建环境', align:'center', minWidth: 100}
                ,{field:'vLeader', title: '负责人', align:'center', width: 150}
                ,{field:'dtCreateTime', title: '申请时间', align:'center', minWidth: 160}
                ,{field:'dtModifyTime', title: '构建时间', align:'center', minWidth: 160}
                ,{field:'eAudit', title: '审核状态',  align:'center', width: 100}
                ,{fixed: 'right', width:350, align:'center', toolbar: '#EditBaseServer'}
            ]],
            where: {
                vServerName: '',
                vLeader: '',
                eAudit: ''
            },
            request: {
                //页码的参数名称，默认：page
                pageName: 'pageNumber',
                //每页数据量的参数名，默认：limit
                limitName: 'pageSize'
            },
            response: {
                //数据总数的字段名称，默认：count
                countName: 'total',
                //数据列表的字段名称，默认：data
                dataName: 'rows'
            }
        });
        var $ = layui.$, active = {
            /*表格重载*/
            reload: function(){
                var vServerName = $('#buildName');
                var eAudit = $('#eAudit');
                var vLeader = $('#BuildLeader');

                table.reload('buildRecordID', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        vServerName: vServerName.val(),
                        eAudit: eAudit.val(),
                        vLeader: vLeader.val(),
                    }
                });
            },
        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('.layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        table.on('tool(table)', function(obj){
            var data = obj.data;
            var S= data.vServerName.substring(0,2)
            if(obj.event === 'audit'){
                if (data.eAudit ==="已审核"){
                    layer.alert("已构建审核不能再次构建")
                } else {
                    layer.confirm('开始构建吗', function(index){
                        $.ajax({
                            url: "/server/buildAudit?buildId=" + data.buildId,
                            success: function(data) {
                                if (data == "true") {layer.alert("成功!")} else {layer.alert("失败了!")}
                            }
                        })

                    });
                }

            }else if(obj.event==='LogOne'){
                if(S==="BA"){loadPageWithBlank("http://git.woda.ink/woda/services/BrokerAssistant/"+data.vServerName+"/commits/master") }
                else if (S==="BK") {loadPageWithBlank("http://git.woda.ink/woda/services/Broker/"+data.vServerName+"/commits/master")}
                else if (S==="BZ") {loadPageWithBlank("http://git.woda.ink/woda/services/business/"+data.vServerName+"/commits/master")}
                else if (S==="OP") {loadPageWithBlank("http://git.woda.ink/woda/services/Operation/"+data.vServerName+"/commits/master")}
                else if (S==="AT") {loadPageWithBlank("http://git.woda.ink/woda/services/Audit/"+data.vServerName+"/commits/master")}
                else if (S==="SIN") {loadPageWithBlank("http://git.woda.ink/woda/services/Finance/"+data.vServerName+"/commits/master")}
            }
        });
    });
    function loadPageWithBlank(url) {
        window.open(url);
    }
    function loadPage(url) {
        window.location.href = url;
    }
    function one(){
        loadPage("/server/baseServer")
    }
    function three(){
        loadPage("/server/buildAuditList")
    }
    function four(){
        loadPage("/server/buildApply")
    }
</script>
<script type="text/html" id="EditBaseServer">
    <a class="layui-btn layui-btn-xs" lay-event="LogOne">查看编译日志</a>
    <a class="layui-btn layui-btn-xs" lay-event="LogTow">查看部署日志</a>
</script>

</body>
</html>